#ifndef __DEBUG_H__
#define __DEBUG_H__

#include <stdio.h>
#include <unistd.h>
#include <time.h>
#include <sys/stat.h>

#define DEBUG_LOG   "./lib/debug_log.txt"

#ifdef _DEBUG_
#define DEBUG(format,...) \
        printf("FILE:" __FILE__ ",LINE:%05d:" format, __LINE__,##__VA_ARGS__); \
        do { \
        if (access("./lib", F_OK) != 0) \
            mkdir("./lib", 0777); \
        FILE * fp_debug = NULL; \
        fp_debug = fopen(DEBUG_LOG, "ab+"); \
        fprintf(fp_debug, "[BUG]--" " FILE: " __FILE__ ", LINE:%04d:" format, __LINE__, ##__VA_ARGS__); \
        fclose(fp_debug); \
    } while (0)

#else 
#define DEBUG(format,...)
#endif

#endif